/**
 * Created by wanghongfei2016 on 2017/1/23.
 */
/**
 * Created by wanghongfei2016 on 2017/1/23.
 */
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */



import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    ScrollView,
    TouchableOpacity,
    TextInput,
    Image,
    View
} from 'react-native';

import crewRecruit from './crewRecruit'
export default class generalRecruit extends Component {


    constructor(props) {
        super(props);
        this.state = {  title: '',
            body: '',
            photo: '',
            play_job: '',
            addr: '',
            contact_addr: '',
            contactor: '',
            wx: '',
            qq: '',
            email: ''
        };
    }



    camera=()=>{
        alert('拍照')
    }
    album=()=>{
        alert('相册')
    }
    pressBtn=()=>{
        //出栈，返回到上一页
        const { navigator } = this.props;



        if(navigator) {
            //出栈，返回到上一页
            navigator.pop();
        }
    }
    submit=()=>{
        if (!this.state.title) {
            alert('请输入招聘题目');
            return;
        }
        if (!this.state.play_job) {
            alert('请输入职位');
            return;
        }
        if (!this.state.addr) {
            alert('请输入地址');
            return;
        }
        if (!this.state.contact_addr) {
            alert('请输入联系人地址');
            return;
        }
        if (!this.state.body) {
            alert('请输入要求');
            return;
        }
        if (!this.state.contactor) {
            alert('请输入联系人');
            return;
        }
        if (!this.state.wx) {
            alert('请输入微信');
            return;
        }
        if (!this.state.qq) {
            alert('请输入QQ');
            return;
        }
        if (!this.state.email) {
            alert('请输入电子邮箱');
            return;
        }
//alert('title='+this.state.title+'\n job='+this.state.play_job+'\n 工作地址='+this.state.addr+'\n 联系人'+this.state.contactor+'\n 要求='+this.state.body+'\n QQ='+this.state.qq+'\n WX='+this.state.wx+'\n email='+this.state.email+'\n 联系人地址'+this.state.contact_addr)

        //var b = new Date($scope.user.play_begin);
        //$scope.user.play_begin = b.getFullYear() + '-' + (b.getMonth() + 1) + '-' + b.getDate();


        //var saveData = new FormData();
        let putongData = new FormData();
        putongData.append('id','');

        var  saveData = {
            'id':'',
            'title':this.state.title,
            'play_job':this.state.play_job,
            'addr':this.state.addr,
            'contactor':this.state.contactor,
            'body':this.state.body,
            'wx':this.state.wx,

            'qq':this.state.qq,
            'email':this.state.email,
            'contact_addr':this.state.contact_addr,
            'hr_type':'1132459',

        }
        //var  saveData = {
        //    'id':'',
        //    'title':'1',
        //    'play_job':'2',
        //    'addr':'3',
        //    'contactor':'4',
        //    'body':'5',
        //    'wx':'6',
        //    'qq':'7',
        //    'email':'8',
        //    'contact_addr':'9',
        //    'hr_type':'1132459',
        //
        //}
        saveData=JSON.stringify(saveData);
        putongData.append('saveData',saveData);
        putongData.append('username','18911166164');
        putongData.append('password','wf2006');
        putongData.append('from_client','cc');
        putongData.append('client_ver','0.4.5');



        let logindata = new FormData();

        logindata.append('username','ceshi1981');

        logindata.append('password','300hu');
        logindata.append('from_client','cc');
        logindata.append('client_ver','0.4.5');
        var fetchOptions = {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                //json形式
                'Content-Type': 'multipart/form-data'
            },
            body: putongData
        };

        //
        var url ='http://121.42.49.27:8002/api/cc/act?mod=hr&act=save'
        var url1 = 'http://121.42.49.27:8002/api/cc/act?mod=user3&act=logon'
        fetch(url,fetchOptions)

            .then((response) => response.json())
            .then((responseText) => {
                alert(JSON.stringify(responseText));
            }).done();

    }
    render() {
        return (

            <ScrollView>

                <View style={styles.container}>
                    <View style={styles.btContainer}>
                        <TouchableOpacity onPress={this.pressBtn} style={styles.crewBtn}>
                            <Text style={styles.crewText}>剧组招聘</Text>
                        </TouchableOpacity>

                        <TouchableOpacity style={styles.generalBtn}>
                            <Text style={styles.generalText}>普通招聘</Text>

                        </TouchableOpacity>
                    </View>

                    <View style={styles.container1}>
                        <View style={styles.itemTopView}>
                            <Text style={styles.nameLabel}>招聘项目</Text>
                            <View style={styles.lineView}></View>
                            <TextInput onChangeText={(text) => {this.state.title=text}}  style={styles.inputBox1} placeholder="如:玄幻大戏'西游'剧组招募"/>
                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>招聘职位</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.play_job=text}} style={styles.inputBox1} placeholder="请输入招聘职位"/>

                            </View>

                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>工作地</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.addr=text}} style={styles.inputBox1} placeholder="请输入工作地"/>


                            </View>

                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>联系人</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.contactor=text}} style={styles.inputBox1} placeholder="请输入联系人"/>


                            </View>

                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>要求</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.body=text}} style={styles.inputBox1} placeholder="请输入要求"/>


                            </View>

                        </View>
                    </View>



                    <View style={styles.container3}>
                        <View style={styles.itemMidView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>QQ</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.qq=text}} style={styles.inputBox1} placeholder="请输入QQ"/>

                            </View>
                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>微信</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.wx=text}} style={styles.inputBox1} placeholder="请输入微信"/>

                            </View>
                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>邮箱</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.email=text}} style={styles.inputBox1} placeholder="请输入邮箱"/>

                            </View>
                        </View>
                        <View style={styles.itemBottomView}>
                            <View style={styles.itemTopView}>
                                <Text style={styles.nameLabel}>联系地址</Text>
                                <View style={styles.lineView}></View>
                                <TextInput onChangeText={(text) => {this.state.contact_addr=text}} style={styles.inputBox1} placeholder="请输入联系地址"/>

                            </View>
                        </View>

                    </View>

                    <Image style={styles.photo} source={require('./favicon.png')}/>


                    <View style={styles.getPhoto}>
                        <TouchableOpacity onPress={this.camera} style={styles.camera}><Text style={styles.cameraText}>拍照</Text></TouchableOpacity>
                        <TouchableOpacity onPress={this.album} style={styles.album}><Text style={styles.albumText}>相册</Text></TouchableOpacity>

                    </View>
                    <TouchableOpacity onPress={this.submit} style={styles.submit}>
                        <Text style={styles.submitText}>提交</Text>
                    </TouchableOpacity>

                </View>
            </ScrollView>
        );
    }
}

const styles = StyleSheet.create({
    container: {

        //flex: 1,
        justifyContent: 'space-between',
        alignItems: 'center',
        backgroundColor: '#f0f0f0',
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
        alignItems:'flex-end',
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },


    btContainer:{
        width:330,
        height:50,
        marginTop:30,
        backgroundColor: '#fff0ff',
        flexDirection:'row',

    },
    crewBtn:{
        width:110,
        height:40,


        backgroundColor: '#eeefff',
    },
    crewText:{
        width:110,
        height:40,
        textAlign: 'center',
        fontSize:22,
        marginTop:10,

        backgroundColor: '#eeefff',
    },
    generalBtn:{
        width:220,
        height:40,
        backgroundColor: '#fff0ff',
    },
    generalText:{
        width:220,
        height:40,
        textAlign: 'center',
        fontSize:22,
        marginTop:10,

        backgroundColor: '#fff0ff',
    },

    container1:{

        alignItems: 'center',
        backgroundColor: '#ffffff',
        width:330,
        height:250,
        marginTop:20,
        //marginBottom:400,
    },
    container2:{

        //alignItems: 'center',
        backgroundColor: '#ffffff',
        width:330,
        height:350,
        marginTop:20,
        //marginBottom:400,


    },
    container3:{

        //alignItems: 'center',
        backgroundColor: '#ffffff',
        width:330,
        height:200,
        marginTop:20,
        //marginBottom:100,


    },
    itemTopView:
    {
        alignItems: 'flex-start',
        backgroundColor: '#fff0f0',
        flexDirection:'row',
        width:330,
        height:50,
        borderWidth:0.5,

    },
    itemMidView:
    {
        alignItems: 'flex-start',
        backgroundColor: '#fff0f0',
        flexDirection:'row',
        width:330,
        height:50,
        borderBottomWidth:0.5

    },

    itemBottomView:
    {
        alignItems: 'flex-start',
        backgroundColor: '#fff0f0',

        width:330,
        height:50,
        borderBottomWidth:0.5,
        borderLeftWidth:0.5,
        borderRightWidth:0.5,

    },
    nameLabel:{
        //backgroundColor: '#fff0ff',
        fontSize: 18,
        textAlign: 'center',
        marginTop:15,
        width:100,
        height:30,
        borderRightWidth:1,
    },
    lineView:{
        width:1,
        height:30,
        marginTop:10,
        backgroundColor: '#000000',

    },
    inputBox1:{
        width:200,
        height:30,
        marginTop:10,
        marginLeft:10,
        //backgroundColor: '#00ffff',

    },
    photo:{
        marginTop:20,
        width:150,
        height:180,
        //backgroundColor: '#00ffff',

    },

    getPhoto:{
        marginTop:20,
        flexDirection:'row',
        alignItems: 'flex-start',

        width:150,
        height:25,
        backgroundColor: '#00ffff',

    },
    camera:{
        //fontSize:22,

        width:50,
        height:25,
        backgroundColor: '#00ff00',

    },
    cameraText:{
        fontSize:22,
    },
    albumText:{
        fontSize:22,
    },
    album:{
        marginLeft:50,
        //fontSize:22,

        width:50,
        height:25,
        backgroundColor: '#00ff00',

    },

    submit:{
        marginTop:20,
        marginBottom:30,
        flexDirection:'row',
        alignItems: 'flex-start',
        //textAlign: 'center',
        //fontSize:24,
        width:150,
        height:50,
        backgroundColor: '#00ffff',
    },
    submitText:{
        marginTop:0,
        //marginBottom:0,
        flexDirection:'row',
        alignItems: 'flex-start',
        textAlign: 'center',
        fontSize:24,
        width:150,
        height:50,
        backgroundColor: '#00ffff',
    }
});

